"""
１．数据库的配置
２．redis配置
３．session配置
４．csef配置
５．日志配置
"""

from flask import Flask
from flask import session
from flask_session import Session
from flask_sqlalchemy import SQLAlchemy
import redis
from flask_wtf.csrf import CSRFProtect


app = Flask(__name__)

# 配置信息
class Config(object):
    SECRET_KEY = "kjsdhfjkfsdhgkj"

    SQLALCHEMY_DATABASE_URI = "mysql+pymysql://root:mysql@127.0.0.1:3306/information12"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # 配置redis信息
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379

    # 设置session配置　Session
    SESSION_TYPE = "redis"  # 指定 session 保存到 redis 中
    SESSION_USE_SIGNER = True  # 让 cookie 中的 session_id 被加密签名处理
    SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT)  # 使用 redis 的实例
    PERMANENT_SESSION_LIFETIME = 86400  # session 的有效期，单位是秒


# 从类中加载配置信息到app
app.config.from_object(Config)


# 1.创建ＳＱＬ对象关联app
db = SQLAlchemy(app)


# 2.配置redis
redis_store = redis.StrictRedis(host=Config.REDIS_HOST, port=Config.REDIS_PORT, decode_responses=True)

CSRFProtect(app)

#3.设置session初始化信息
Session(app)

@app.route("/")
def hello_python():

    # 测试redis数据存储
    redis_store.set("name","xiaobai")

    session["name"] = "xiaohei"


    return "hello python"


if __name__ == '__main__':
    app.run(debug=True)